<template>
    <div>
        <Row style="margin:5px 0px 10px 5px">
            <i-col span="1" >
                <Button  size="default"  type="primary" @click="btn_refresh">刷新</Button>
            </i-col>
        </Row>
        <i-table size="default"   border stripe  :columns="format" :data="show_list" :height="sharedState.tableHeight" >
            <template slot-scope="{ row, index }" slot="action">
                <Button  size="default"  type="primary"   style="margin-bottom: 5px "  @click="play_record(index)">回放</Button>
            </template>
        </i-table >
        <div style="text-align: center;margin-top: 10px;">
            <Page ref="page" :total="total" :page-size="pageSize"  @on-change="changePage" show-total/>
        </div>

    </div>
</template>
<script>

import { record_list } from  '@/api'
import { post } from '@/api/http'
import store from '@/store'
import { show_simple_page } from '@/common/util' 

export default {

    data() {
        return {
            sharedState: store.state,
            format: [
                {
                    title: '序号',key: 'id'
                },
                {
                    title: '主机',key: 'host'
                },
                {
                    title: '登录用户',key: 'username'
                },
                {
                    title: '文件名',key: 'filename'
                },
                {
                    title: '下载地址',key: 'download_url'
                },
                {
                    title: '开始时间',key: 'start_time'
                },
                {
                    title: '结束时间',key: 'end_time'
                },
                {
                    title: '操作',slot: 'action',width: 150,align: 'center'
                }
            ],
            // 分页
            total_list: [],
            show_list: [],
            total: 0,
            pageSize: 50,
            show_record_modal: false,
            download_url: '',
        }
    },
    methods: {
        btn_refresh(){
            this.refresh()
        },
        play_record(index){
            let id = this.show_list[index].id
            let record_url = process.env.VUE_APP_RECORD_URL
            window.open(record_url+"?id="+id,"_blank");
        },
        changePage(index) {
            let _start = (index -1) * this.pageSize
            let _end = index * this.pageSize
            this.show_list = this.total_list.slice(_start,_end)
        },
        refresh() {
            let cluster = localStorage.getItem('currentEsCluster')
            let headers = {"cluster_name": cluster }
            post(record_list,undefined,headers).then(response =>{
                show_simple_page(this,response)
            })
        }
    },
    mounted: function() {
        setTimeout(() =>{
            this.refresh();
        },200); 
    }
}
</script>
<style>
    pre{
        white-space: pre-wrap!important;
        word-wrap: break-word!important;
        *white-space:normal!important;
    }
</style>